/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.icanci.learn.v1.aspcet;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

/**
 * @author icanci
 * @date Created in 2021/06/29 22:23
 * @version 1.0
 */
@Aspect
public class AspectConfig {

    /**
     * 如何定义一个切点
     * 切点位置：cn.icanci.learn 所有class以Test结尾的方法
     */
    @Pointcut(value = "execution(* cn.icanci.learn..*.*Test(..))")
    public void test() {

    }

    /**
     * 前置通知
     */
    @Before(value = "test()")
    public void before() {
        System.out.println("AspectConfig.before");
    }

    /**
     * 后置通知
     */
    @After(value = "test()")
    public void after() {
        System.out.println("AspectConfig.after");
    }

    /**
     * 前置通知
     */
    @Around(value = "test()")
    public void around(ProceedingJoinPoint joinPoint) {
        try {
            System.out.println("AspectConfig.around begin");
            joinPoint.proceed();
            System.out.println("AspectConfig.around end");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
